import { defineStore } from 'pinia'
import { ref } from 'vue'
import { ResLoginInfo, getQueryOemCode2Api } from '@/api'

// 初始化状态
const oemInfoState: ResLoginInfo = {
  id: -1,
  oemCode: "", //OEM机构编码
  oemName: "", //OEM机构名称（品牌名称）
  oemCompanyName: "", //OEM机构对应企业名称
  logoFile: [],
  icoFile: [],
  themeColor: "",
  address: "", //地址
  hotline: "", //联系电话
  icp: "", //ICP备案信息
  enterpriseParkName: "", //园区个性化名称 - 后台/合伙人小程序端
  workerParkName: "", //园区个性化名称 - 零工小程序端
  defaultPartnerName: "", //默认合伙人等级名称
  level1PartnerName: "", //合伙人等级个性化名称 - 一级合伙人
  level2PartnerName: "", //合伙人等级个性化名称 - 二级合伙人
  partyCode: "",
  position: "", //平台定位
  introduce: "", //一句话介绍
  subIntroduce: "", //辅介绍
  config: "", //贴牌配置参数信息，json格式
}

export const useOemStore = defineStore(
  'oem',
  () => {
    // 定义oem信息
    const oemInfo = ref<ResLoginInfo>({ ...oemInfoState })
    // 设置oem信息
    const setOemInfo = (val: ResLoginInfo) => {
      oemInfo.value = val
    }
    /**
     * 获取OEM信息
     */
    const getQueryOemCode2 = async () => {
      const data = await getQueryOemCode2Api(location.hostname === "localhost" ? "linggong.runzhixx.cn" : location.hostname)
      console.log(data)
      setOemInfo(data)
      return data
    }
    return {
      oemInfo,
      setOemInfo,
      getQueryOemCode2
    }
  },
  {
    persist: true,
  },
)
